package com.situ.blog.controller;

import com.situ.blog.pojo.User;
import com.situ.blog.service.IUserService;
import com.situ.blog.util.JSONResult;
import com.situ.blog.util.LayUITableJSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @RequestMapping("/deleteById")
    @ResponseBody
    public JSONResult deleteById(Integer id) {
        return userService.deleteById(id);
    }

    @RequestMapping("/add")
    @ResponseBody
    public JSONResult add(User user) {
        //JSONResult jsonResult = userService.add(user);
        //return jsonResult;

        return userService.add(user);
    }

    @RequestMapping("/getUserAddPage")
    public String getUserAddPage() {
        return "/WEB-INF/user_add.jsp";
    }

    @RequestMapping("/getUserListPage")
    public String getUserListPage() {
        return "/WEB-INF/user_list.jsp";
    }

    // /user/selectByPage?page=1&limit=10
    @RequestMapping("/selectByPage")
    @ResponseBody
    public LayUITableJSONResult selectByPage(Integer page, Integer limit) {
        LayUITableJSONResult layUITableJSONResult = userService.selectByPage(page, limit);
        return layUITableJSONResult;
    }

    @RequestMapping("/selectAll")
    @ResponseBody
    public List<User> selectAll() {
        List<User> list = userService.selectAll();
        return list;
    }
}
